BeSly Software Solutions About yab Demos About us Admin






Name:

right$() -- return (or change) the right end of a string

Synopsis:
print right$(a$,2) 
right$(b$,2)="baz" 

Description:
The right$-function requires two arguments (a string and a number) and returns the part from the right end of the string, whose length is specified by its second argument. So, right$ simply returns the requested number of chars from the right end of the given string.
Note, that the right$-function can be assigned to, i.e. it may appear on the left hand side of an assignment. In this way it is possible to change a part of the variable used within the right$-function. Note, that that way the length of the string cannot be changed, i.e. characters might be overwritten, but not added. For an example see below.

Example:
print "Please enter a length either in inch or centimeter" 
print "please add 'in' or 'cm' to mark the unit." 
input "Length: " a$ 
if (right$(a$,2)="in") then 
	length=val(a$)*2.56 
elsif (right$(a$,2)="cm") then 
	length=val(a$) 
else 
	error "Invalid input: "+a$ 
endif 

a$="Heiho World!" 
print a$ 
right$(a$,7)="dwarfs." 
print a$ 
Explanation:

This program allows the user to enter a length qulified with a unit (either inch or centimeter).
The second example demonstrates the capability to assign to the right$-function.
 


Related: right$, mid$